<!DOCTYPE html>
<html lang="en">
<head>
    <base href="../../">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="css/layui.css">
    <title>创建开关</title>
</head>
<body>
    <div class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">标签名</label>
            <div class="layui-input-block">
                <input type="text" name="name" id="name" lay-verify="required" lay-reqtext="开关标签不能为空" placeholder="请输入开关标签" value="" class="layui-input">
                <tip>开关左侧显示的文字</tip>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否必选</label>
            <div class="layui-input-block">
                <input type="checkbox" name="isRequired" id="isRequired"  value="true" lay-skin="switch" lay-text="必填|不必">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">打开时文字</label>
            <div class="layui-input-block">
                <input type="text" name="switch_open" id="switch_open" lay-verify="required" lay-reqtext="开启时文字不能为空" placeholder="请输入输入开启时文字" value="打开" class="layui-input">
                <tip>开关开启时显示的文字, 建议1~2个字符</tip>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">关闭时文字</label>
            <div class="layui-input-block">
                <input type="text" name="switch_close" id="switch_close" lay-verify="required" lay-reqtext="关闭时文字不能为空" placeholder="请输入输入关闭时文字" value="关闭" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">创建</button>
            </div>
        </div>
    </div>

    <script src="layui.js"></script>
    <script>
        layui.use('form',function(){
            var form = layui.form;

            //监听提交
            form.on('submit(saveBtn)', function (data) {
                console.log("data",data,data.field);
                parent.layui.data("form_data",{
                    key: "carry",
                    // value: JSON.stringify(data.field)
                    value: data.field
                });
                
                var iframeIndex = parent.layer.getFrameIndex(window.name);
                parent.layer.close(iframeIndex);
            });
        });
    </script>
</body>
</html>